<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage Commercial core plugins
 */


/**
 * Smarty `config` modifier plugin
 *
 * Type:     modifier<br>
 * Name:     config<br>
 * Date:     Oct 20, 2008
 * Purpose:  fetch from configs variables
 * Input:    string
 * Example:  {$v|config}
 *           {'title'|config}
 * @author   Alex Yaroshevich <qfox@ya.ru>
 * @version 0.1
 * @param string with url
 * @return string
 */
function smarty_modifier_config( $v, $data = null )
{
	$v = str_replace( '.', '__', $v );
	$r = config::__getMe( ) ->$v;
	
	if( !is_null( $data ) )
	{
		if( is_string( $data ) )
		{
			$_data = func_get_args( );
			array_shift( $_data );
			$keys = explode( ',', array_shift( $_data ) );
			if( count( $keys ) )
			{
				$data = array( );
				foreach( $keys as $k )
				{
					$data[ $k ] = array_shift( $_data );
				}
			}
		}
		if( is_array( $data ) )
		{
			$r = str_replace( array_map( create_function( '$a', 'return "{{$a}}";' ), array_keys( $data ) ), array_values( $data ), $r );
		}
	}
	
	return $r;
}

/* vim: set expandtab: */

?>